<?php
require_once('ngdom.database.php');
if(ngdom_db_getval("show tables like 'ngdom_users'") == 'ngdom_users') {
	header("HTTP/1.0 404 Not Found", true, 404);
}
else {  
  	ngdom_db_query("
		CREATE TABLE `ngdom_users` (
		  `id` bigint(20) unsigned NOT NULL auto_increment,
		  `user_email` varchar(255) NOT NULL,
		  `user_pass` varchar(60) NOT NULL,
		  `secret` binary(128) default NULL,
		  `facebookId` bigint(20) unsigned NOT NULL,
		  `created` datetime NOT NULL,
		  `last_played` datetime NOT NULL,
		  `pass_reset_token` binary(32) default NULL,
		  `pass_reset_time` datetime default NULL,
		  PRIMARY KEY  (`id`),
		  UNIQUE KEY `user_email` (`user_email`),
		  UNIQUE KEY `secret` (`secret`),
		  UNIQUE KEY `pass_reset_token` (`pass_reset_token`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1;

		CREATE TABLE `ngdom_save` (
		  `id` bigint(20) unsigned NOT NULL auto_increment,
		  `user_id` bigint(20) unsigned NOT NULL,
		  `game` varchar(255) NOT NULL,
		  `slot` int(10) unsigned NOT NULL default '1',
		  `savedata` text NOT NULL,
		  `created` datetime NOT NULL,
		  `last_played` datetime NOT NULL,
		  PRIMARY KEY  (`id`),
		  UNIQUE KEY `Unique_Save` (`user_id`,`game`,`slot`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1;
	");
	echo "database installed successfully.";
}
?>